<template>
	<view class="items">
		<view class="food-head">
			<image :src="details.apCookbook.picture" @click="previewImg(details.apCookbook.picture)" mode="aspectFill">
			</image>
			<view class="food-name">
				<view class="name-txt">
					{{details.apCookbook.name}}
				</view>
			</view>
		</view>

		<!-- 菜谱简介 -->
		<view class="food-inrduc">
			<view class="inrduc-center">
				<text class="online">——</text>
				<text class="txt" style="color: #000000;">菜谱简介</text>
				<text class="online">——</text>
				<text class="fuhao">▼</text>
			</view>
			<view class="content">{{details.apCookbook.description}}</view>
		</view>


		<view style="margin-left: 50%;transform: translate(-50%);">
			<!-- 用料 -->
			<view class="inrduc-center">
				<text class="online">——</text>
				<text class="txt">用料信息</text>
				<text class="online">——</text>
				<text class="fuhao">▼</text>
			</view>
			<view>
				<view v-for="item in details.cookbookIngredientList" :key="item"
					style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;width: 100%;height: 80upx;">
					<view> {{item.name}}</view>
					<view> {{item.amount}}</view>
				</view>
			</view>

		</view>

		<view class="food-step">




			<!-- 做法步骤 -->
			<view class="inrduc-center">
				<text class="online">——</text>
				<text class="txt">做法步骤</text>
				<text class="online">——</text>
				<text class="fuhao">▼</text>
			</view>
			<view class="prepare" v-for="item in details.cookbookInstructionList" :key="item.id">
				<image :src="item.url" mode="aspectFill"></image>
				<view class="steps">
					<text style="color: orange;font-size: 30px;">{{item.step}}</text>
					<text>/</text>
					<!-- <text style="color: orange;">{{len-n}}</text> -->
					<view>{{item.description}}</view>
				</view>
			</view>


			<!-- 底部导航 -->
			<view class="goods_nav">
				<view class="tab">
					<view class="tab_item" @click="handleflag">
						<uni-icons type="heart" size="20" v-if="!flag"></uni-icons>
						<uni-icons type="heart-filled" size="20" color='red' v-if="flag"></uni-icons>
						<view>收藏</view>
					</view>
					<view class="tab_item" @click="goIndex">
						<uni-icons type="home" size="20"></uni-icons>
						<view>首页</view>
					</view>
					<view class="tab_item">
						<!-- #ifdef H5 -->
						<uni-icons type="redo" size="20"></uni-icons>
						<view class="" @click="shareOn">分享</view>
						<uni-popup ref="sharepopup" type="bottom">
							<share-btn :sharedataTemp="sharedata"></share-btn>
						</uni-popup>
						<!-- #endif -->
						<!-- #ifdef MP-ALIPAY -->
						<uni-icons type="redo" size="20"></uni-icons>
						<view class="tab-btn">
							<button open-type="share" class="share-btn" v-if="canIUseShareButton">分享</button>
						</view>
						<!-- #endif -->
						<!-- #ifdef MP-WEIXIN -->
						<uni-icons type="redo" size="20"></uni-icons>
						<view class="tab-btn"><button class="share-btn" open-type="share">分享</button></view>
						<!-- #endif -->
					</view>
				</view>
				<view class="btn">
					<button @click='buttonClick' class="btn-left">加入菜篮子</button>
					<button @click='goCart' class="btn-right">去看看</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations,
		mapGetters
	} from 'vuex'
	import {
		myRequestPost
	} from '@/utils/request.js';
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	import shareBtn from '@/components/share-btn/share-btn.vue';
	import uniIcons from "@/components/uni/uni-icons/uni-icons.vue";

	import {
		cookbook_detail
	} from '@/api/ap_cookbook.js'

	import {
		user_collect
	} from '@/api/user_collect.js'

	import {
		user_join
	} from '@/api/user_cart.js'
	export default {
		components: {
			uniPopup,
			shareBtn,
			uniIcons
		},
		data() {
			return {
				foodId: "",
				details: {},
				prepare: [],
				step1: [],
				len: "",
				step_length: "",
				count: "",
				flag: false,
				title: "",
				obj: {},
				detailStorge: "",
				n: 0,
				accessory: [],
				main: [],
				canIUseShareButton: true,
				sharedata: {
					type: 1,
					strShareUrl: "http://www.baidu.com",
					strShareTitle: "分享标题",
					strShareSummary: "分享总结",
					strShareImageUrl: "http://www.xuelejia.com/xljapp/h5/static/aboutUsLogo.png"
				}
			}
		},
		onLoad(options) {
			this.foodId = options.foodId;
			console.log(this.foodId)
			this.getDetails();
		},
		// #ifdef MP-ALIPAY
		setShareButtonSwitch() {
			this.setData({
				canIUseShareButton: my.canIUse('button.open-type.share')
			})
		},
		// #endif
		onShareAppMessage(res) {
			return {
				title: "美食分享",
				path: "pages/themeDetails/themeDetails"
			}
		},
		computed: {
			...mapState({
				menus: "menus"
			})
		},

		methods: {

			userCollect() {

			},

			getDetails() {
				let params = {}
				params.id = this.foodId
				cookbook_detail(params).then(res => {
					console.log(res)
					if (res.code === '200') {
						this.details = res.data
						this.flag = res.data.collect
					} else {
						uni.navigateTo({
							url: '../login/login'
						})
					}

				})
			},
			//收藏保存数据
			handleflag() {
				let params = {}
				if (!this.flag) {
					params.type = 1;
				} else {
					params.type = 2
				}
				params.foodId = this.foodId
				user_collect(params).then(res => {
					if (res.code === '200') {
						if (!this.flag) {
							uni.showToast({
								title: '收藏成功'
							})
							this.flag = true
						} else {
							uni.showToast({
								title: '取消成功'
							})
							this.flag = false
						}
					}
				})
			},

			previewImg(imageUrl) {
				console.log(imageUrl)
				var images = [];
				images.push(imageUrl);
				console.log(images)
				uni.previewImage({ // 预览图片  图片路径必须是一个数组 => ["http://192.168.100.251:8970/6_1597822634094.png"]
					current: 0,
					urls: images
				});
			},
			goIndex() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			shareOn() {
				this.$refs.sharepopup.open();
			},
			buttonClick(e) {
				let params = {}
				params.type = 1;
				params.foodId = this.foodId
				user_join(params).then(res => {
					if (res.code === '200') {
						uni.showToast({
							title: '加入成功',
							icon: 'none'
						})
					}
				})

			},
			goCart() {
				uni.navigateTo({
					url: '/pages/cart/cart'
				})
			}

		}
	}
</script>

<style lang="scss">
	.items {
		display: flex;
		box-sizing: border-box;
		flex-wrap: wrap;
		font-family: "楷体";

		.food-head {
			position: relative;

			image {
				width: 750rpx;
				height: 550rpx;
				background-size: cover;
			}

			.food-name {
				position: absolute;
				bottom: -80rpx;
				left: 50%;
				margin-left: -37rpx;
				padding: 10rpx;
				width: 60rpx;
				background-color: rgba($color: #fff, $alpha: 0.81);
				opacity: 0.7;
				border-radius: 30rpx;
				text-align: center;

				.name-txt {
					padding: 13rpx 12rpx;
					border: 1rpx solid #000;
					font-size: 33rpx;
					border-radius: 20rpx;
					color: #000;
					line-height: 43rpx;
				}
			}
		}

		.food-inrduc {
			width: 710rpx;
			margin-top: 100rpx;
			margin-bottom: 40rpx;
			margin-left: 20rpx;
			color: #979797;

			.content {
				margin-left: 38rpx;
				text-indent: 2em;
			}
		}

		.meterials {
			margin-left: 50rpx;
			margin-bottom: 20rpx;
		}

		.goods_nav {
			position: fixed;
			display: flex;
			bottom: 0;
			width: 100%;
			background-color: #fff;

			.tab {
				display: flex;
				padding: 0 5px;
				font-size: 12px;

				.tab_item {

					margin: 0 10px;
					margin-top: 15rpx;

					.tab-btn {
						border: 0;

						.share-btn {
							// width: 80rpx;
							height: 38rpx;
							padding: 0;
							background-color: #fff;
							line-height: 27rpx;
							font-size: 12px;
							border: none;
							outline: none;
						}

						/* #ifdef MP-ALIPAY */
						.share-btn {
							// width: 80rpx;
							height: 30rpx;
							padding: 0;
							background-color: #fff;
							line-height: 27rpx;
							font-size: 12px;
							border: none;
							outline: none;
						}

						/* #endif */
					}
				}
			}

			.btn {
				float: right;
				display: flex;
				width: 446rpx;
				height: 80rpx;
				margin: 5px 0;
				margin-right: 10px;
				overflow: hidden;

				button {
					height: 80rpx;
					line-height: 80rpx;
					font-size: 14px;

					flex: 1;
				}

				button::after {
					border: none;
				}

				.btn-left {
					border-top-left-radius: 200rpx;
					border-bottom-left-radius: 200rpx;
					background-color: #ff0000;
					color: #fff;
				}

				.btn-right {
					border-top-right-radius: 200rpx;
					border-bottom-right-radius: 200rpx;
					background-color: #ffa200;
					color: #fff;
				}
			}
		}

		.inrduc-center {
			text-align: center;
			color: orange;

			.txt {
				font-size: 35rpx;
				font-weight: 520;
				padding: 0 20rpx;
			}

			.fuhao {
				display: block;
			}

		}

		.food-ingred {
			width: 650rpx;
			height: 50rpx;
			line-height: 50rpx;
			color: #333;
			margin: 0 auto;
			border-bottom: 1px solid #ccc;

			text {
				margin-left: 130rpx;
			}

			.text-right {
				margin-right: 150rpx;
				float: right;
			}
		}

		.food-step {
			display: flex;
			box-sizing: border-box;
			flex-wrap: wrap;

			.inrduc-center {
				margin-left: 212rpx;
			}

			image {
				width: 640rpx;
				height: 600rpx;
				margin-left: 55rpx;
				background-size: cover;
			}

			.food-step-desc {
				width: 670rpx;
				margin-left: 40rpx;
				line-height: 36rpx;
				margin-bottom: 20rpx;
			}

			.steps {
				display: flex;
				box-sizing: border-box;
				margin: 10rpx 0 10rpx 50rpx;

				.desc {
					width: 580rpx;
					padding-left: 5rpx;
					letter-spacing: 2rpx;
					line-height: 40rpx;
					color: #666;
					text-indent: 1em;
				}
			}

			.food-step-main {
				width: 680rpx;
			}
		}

		.footer {
			width: 750rpx;
			height: 100rpx;
			background-color: #FFFFFF;
			margin: 40rpx auto;
		}
	}
</style>